package _case

import "fmt"

type user struct {
	Name string
	Age  uint
	Addr Address
}

type Address struct {
	Province string
	City     string
}

func StructCase() {
	// 值类型
	u := user{
		Name: "zn",
		Age:  22,
	}
	f2(u)
	fmt.Println(u)
	// 指针类型
	u1 := &user{
		Name: "zn1",
		Age:  17,
	}
	f3(u1)
	fmt.Println(u1)
	// 指针类型
	u2 := new(user)
	u2.Name = "zn3"
	u2.Age = 20
	fmt.Println(u2, u2.Addr.Province)

	// 结构体为值类型，定义变量后将被默认初始化, 如果是指针类型有nil, 若直接使用可能空指针
	var u3 user
	fmt.Println(u3)
}

func f2(u user) {
	u.Age = 28
}

func f3(u *user) {
	u.Age = 28
}
